<?php
namespace App\Listeners\Trade\Supply;

use App\Core\Entity\Session\UserEntity;
use App\Events\Trade\Supply\RefreshEvent;
use App\Models\Trade\Supply\SupplyRefreshModel;

/**
 * 监听器【商品刷新】
 */
class RefreshListener
{

    /**
     * 用户实体
     *
     * @var \App\Core\Entity\Session\UserEntity
     */
    protected $user;

    /**
     * 创建事件监听器
     *
     * @return void
     */
    public function __construct(UserEntity $user)
    {
        $this->user = $user;
    }

    /**
     * 处理事件
     *
     * @param RefreshEvent $event            
     * @return void
     */
    public function handle(RefreshEvent $event)
    {
        // 添加刷新次数
        SupplyRefreshModel::addItemByToday($this->user->getUserId(), $event->id);
    }
}
